/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.hiddendanger.mapper;

import com.koron.hiddendanger.bean.HiddenDangerDiscoveryCount;
import com.koron.hiddendanger.domain.HiddenDangerDiscovery;
import com.koron.hiddendanger.domain.HiddenDangerRectification;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface HiddenDangerMapper {

    /**
     * 根据主键查询隐患信息
     *
     * @param id
     * @return
     */
    HiddenDangerDiscovery queryDangerOne(@Param("id") String id);

    /**
     * 根据指定条件查询隐患台账列表
     *
     * @param description
     * @param dangerType
     * @param dangerLevel
     * @param corpCode
     * @param gridCode
     * @param checkUnit
     * @param state
     * @param start
     * @param rows
     * @return
     */
    List<HiddenDangerDiscovery> queryMobileDangerByCondition(@Param("description") String description, @Param("dangerType") String dangerType,
                                                             @Param("dangerLevel") String dangerLevel, @Param("codes") String codes,
                                                             @Param("gridCode") String gridCode, @Param("corpCode") String corpCode, @Param("checkUnit") String checkUnit, @Param("state") Integer state, @Param("startTime") Date startTime,
                                                             @Param("endTime") Date endTime, @Param("start") Integer start, @Param("rows") Integer rows,@Param("submitterCode") String submitterCode,@Param("keyword") String keyword);

    List<HiddenDangerDiscovery> queryDangerByCondition(@Param("description") String description, @Param("dangerType") String dangerType,
                                                       @Param("dangerLevel") String dangerLevel, @Param("codes") String codes,
                                                       @Param("gridCode") String gridCode, @Param("checkUnit")String checkUnit, @Param("corpCode")String corpCode, @Param("state") Integer state, @Param("startTime") Date startTime,
                                                       @Param("endTime") Date endTime, @Param("start") Integer start, @Param("rows") Integer rows);

    List<HiddenDangerDiscovery> queryDangerByCondition1(@Param("description") String description, @Param("dangerType") String dangerType,
                                                       @Param("dangerLevel") String dangerLevel, @Param("codes") String codes,
                                                       @Param("gridCode") String gridCode, @Param("checkUnit")String checkUnit, @Param("corpCode")String corpCode, @Param("state") Integer state, @Param("startTime") Date startTime,
                                                       @Param("endTime") Date endTime,@Param("submitterCode") String submitterCode,
                                                        @Param("ids") List<String> ids);

    /**
     * 根据指定条件统计隐患台账
     *
     * @param description
     * @param dangerType
     * @param dangerLevel
     * @param corpCode
     * @param gridCode
     * @param checkUnit
     * @param state
     * @return
     */
    Integer countMobileDangerByCondition(@Param("description") String description, @Param("dangerType") String dangerType,
                                         @Param("dangerLevel") String dangerLevel, @Param("codes") String codes,
                                         @Param("gridCode") String gridCode, @Param("corpCode") String corpCode,  @Param("checkUnit") String checkUnit, @Param("state") Integer state, @Param("startTime") Date startTime,
                                         @Param("endTime") Date endTime,@Param("submitterCode")String submitterCode,@Param("keyword") String keyword);

    /**
     * 根据检查记录id查询隐患列表
     *
     * @param checkRecordId
     * @param start
     * @param rows
     * @return
     */
    List<HiddenDangerDiscovery> queryDangerByCheckRecordId(@Param("checkRecordId") String checkRecordId, @Param("start") Integer start, @Param("rows") Integer rows);

    /**
     * 根据 checkRecordId 查询隐患 id 列表
     * @param checkRecordId
     * @return
     */
    @Select("SELECT id FROM hidden_danger_discovery WHERE check_record_id = #{checkRecordId}")
    List<String> getIdByCheckRecordId(String checkRecordId);

    /**
     * 根据检查记录id查询隐患记录
     *
     * @param checkRecordId
     * @return
     */
    Integer countDangerByCheckRecordId(@Param("checkRecordId") String checkRecordId);

    /**
     * 根据隐患编码进行统计
     *
     * @param code
     * @return
     */
    Integer countCode(@Param("code") String code);

    List<HiddenDangerDiscovery> queryDangerByIdList(@Param("idList") List<String> idList);

    /**
     * 新增隐患记录
     *
     * @param bean
     * @return
     */
    Integer insertDanger(@Param("bean") HiddenDangerDiscovery bean);

    /**
     * 批量新增隐患
     *
     * @param dangerRecordList
     * @return
     */
    Integer batchInsertDanger(@Param("dangerRecordList") List<HiddenDangerDiscovery> dangerRecordList);

    /**
     * 修改隐患记录
     *
     * @param bean
     * @return
     */
    Integer updateDanger(@Param("bean") HiddenDangerDiscovery bean);

    /**
     * 批量修改隐患
     *
     * @param recordList
     * @return
     */
    Integer batchUpdateDanger(@Param("recordList") List<HiddenDangerDiscovery> recordList);

    /**
     * 更新隐患状态
     *
     * @param state
     * @param idList
     * @return
     */
    Integer updateDangerState(@Param("state") Integer state, @Param("idList") List<String> idList);

    Integer updateDangerStateAndOperation(@Param("state") Integer state, @Param("operation") Integer operation, @Param("idList") List<String> idList);

    /**
     * 根据提供的主键列表批量删除隐患记录
     *
     * @param idList
     * @return
     */
    Integer batchDeleteDanger(@Param("idList") List<String> idList);

    /**
     * 查询临时隐患列表
     *
     * @param rectificationState
     * @param start
     * @param rows
     * @return
     */
    List<HiddenDangerDiscovery> queryTempDanger(@Param("rectificationState") String rectificationState, @Param("start") Integer start, @Param("rows") Integer rows);

    /**
     * 统计临时隐患总数
     *
     * @param rectificationState
     * @return
     */
    Integer countTempDanger(@Param("rectificationState") String rectificationState);

    /**
     * 新增隐患整改记录
     *
     * @param rectification
     * @return
     */
    Integer insertRectification(@Param("rectification") HiddenDangerRectification rectification);


    /**
     * 批量新增整改记录
     *
     * @param rectificationList
     * @return
     */
    Integer batchInsertRectification(@Param("rectificationList") List<HiddenDangerRectification> rectificationList);

    /**
     * 修改隐患整改记录
     *
     * @param rectification
     * @return
     */
    Integer updateRectification(@Param("rectification") HiddenDangerRectification rectification);

    Integer bateDeleteRectification(@Param("idList") List<String> idList);

    /**
     * 根据隐患id查询整改列表
     *
     * @param hiddenDangerId
     * @return
     */
    List<HiddenDangerRectification> queryRectificationByDangerRecordId(@Param("hiddenDangerId") String hiddenDangerId);

    /**
     * 根据主键获取隐患整改信息
     *
     * @param id
     * @return
     */
    HiddenDangerRectification queryOneRectificationById(@Param("id") String id);

    /**
     * 获取提交人是当前登录人的草稿数据
     *
     * @param description
     * @param dangerType
     * @param dangerLevel
     * @param submitterCode
     * @param gridCode
     * @param startTime
     * @param endTime
     * @return
     */
    List<HiddenDangerDiscovery> queryDraftDangerByCondition(@Param("description") String description, @Param("dangerType") String dangerType,
                                                            @Param("dangerLevel") String dangerLevel, @Param("submitterCode") String submitterCode,
                                                            @Param("gridCode") String gridCode,@Param("checkUnit") String checkUnit, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    List<HiddenDangerDiscovery> getCheckUnitEmpty();

    Integer batchUpdateCheckUnit(@Param("checkUnitEmpty") List<HiddenDangerDiscovery> checkUnitEmpty);

    List<HiddenDangerDiscovery> homePageList(@Param("corpCode")String corpCode, @Param("codes")String codes, @Param("checkUnit")String checkUnit, @Param("state")Integer state, @Param("startTime")Date startTime, @Param("endTime")Date endTime, @Param("start")Integer start, @Param("rows")Integer rows);

    Integer homePageListCount(@Param("corpCode")String corpCode, @Param("codes")String codes, @Param("checkUnit")String checkUnit, @Param("state")Integer state, @Param("startTime")Date startTime, @Param("endTime")Date endTime);

    List<HiddenDangerDiscovery> queryDangerListByCorpAndTime(@Param("deptCodes")String deptCodes,@Param("checkUnit")String checkUnit, @Param("startTime")Date startTime, @Param("endTime")Date endTime);

    Integer queryDangerCountByCorpAndTime(@Param("deptCodes")String deptCodes,@Param("checkUnit")String checkUnit , @Param("startTime")Date startTime, @Param("endTime")Date endTime);

    /**
     * 通过检查计划Id获取隐患数量
     * @param performancePlanIds
     * @return
     */
    List<HiddenDangerDiscoveryCount> getHiddenDangerDiscoveryCount(@Param("performancePlanIds")List<String> performancePlanIds);

    Integer bateDeleteRectificationByDiscoveryId(@Param("discoveryIdList") List<String> discoveryIdList);
}
